﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>员工管理</title>
    <#include  "../common/link.ftl">
    <script>
        $(function () {
            $('.btn_delete').click(function () {
                var id = $(this).data("id");
                $.messager.confirm("警告", "是否确认删除！", function () {
                    $.get('/employee/delete.do', {id, id}, handlerMessageE)
                });
            });
            $("#allcb").click(function () {
                $('.cb').prop('checked', $(this).prop('checked'));
            });
            $(".cb").click(function () {
                //获取已选中的个数和总个数比较，判断全选是否被选中
                $('#allcb').prop('checked', $('.cb:checked').length == $('.cb').length);
            });
            /*$('.btn_abtchDelete').click(function () {
                if ($('.cb:checked').length == 0) {
                    $.messager.alert("警告", "请选择要删除的记录！");
                    return;
                }
                //获取选中的记录id，保存到数组中。
                var cbs = $('.cb:checked');
                var idsaa = [];
                var idsaa = $.map(cbs, function (ele) {
                    return $(ele).data('ids');
                });
                jQuery.ajaxSettings.transition = true;
                console.log(idsaa);
                //由于jQuery问题，传递过去的数组，会再封装一层括号{}。在原有[]数组的基础上，加一对{}，变成{[]}

                //$.ajaxSettings.transition = true;
                $.messager.confirm("警告", "是否确认删除！", function (data) {
                    $.get('/employee/abtchDelete.do', {ids: idsaa}, function (data) {
                            if (data.success) {
                                /!*重新加载页面*!/
                                $.messager.alert("温馨提示：操作成功 2S后自动关闭");
                                window.setTimeout(function () {
                                    window.location.href = "http://localhost:1998/employee/list.do";
                                }, 2000);
                            } else {
                                $.messager.popup(data.msg);
                            }
                        }
                    );
                });
            });*/
            $('.btn_abtchDelete').click(function () {
                //获取勾选的数据
                //如果没有数据，需要先提示一下。请选择要删除的数据
                if($('.cb:checked') == true){
                    $.messager.alert("警告","请选择要删除的记录");
                    return;
                }
                //获取选中的记录ID。保存到数组中。
                var cbs = $('.cb:checked');
                /* var ids = [];
                 $.each(cbs,function (index,ele) {
                     ids.push($('ele').data('id'));
                 })*/
                var ids =$.map(cbs,function (ele) {
                    return $(ele).data('ids');
                });
                //JQ。传递过去的数据。JQ会在封装一层{}，在原有[]数组基础上再封装一个{}
                //{[4,5]}
                jQuery.ajaxSettings.traditional = true;
                $.messager.confirm("警告","是否确认删除!",function f() {
                    $.get('/employee/abtchDelete.do',{ids:[ids]},handlerMessageE)
                });
            });
            $(".btn-import").click(function(){
                $('#myModal').modal("show");
            });
            $(".btn-import").click(function () {
                $("#myModal").modal('show');
            })
            $(".btn-submitsave").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        /*重新加载页面*/
                        $.messager.alert("温馨提示：操作成功 2s 后自动关闭");
                        window.setTimeout(function () {
                            window.location.href="http://localhost:1998/employee/list.do";
                        }, 2000);
                    } else {
                        $.messager.popup(data.msg);
                    }
                })
            })
        });
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include  "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="employee"/>
    <#include  "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>员工管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <form class="form-inline" id="searchForm" action="/employee/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label for="keyword">关键字:</label>
                            <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}"
                                   placeholder="请输入姓名/邮箱">
                        </div>
                        <div class="form-group">
                            <label for="dept"> 部门:</label>
                            <select class="form-control" id="dept" name="deptId">
                                <option value="-1">全部</option>
                                <#list depts as d>
                                    <option value="${d.id!}">${d.name!}</option>
                                </#list>
                            </select>
                            <script>
                                <#--  $("#dept option[value='${qo.deptId}']").prop("selected", true); -->
                                $("#dept").val(${qo.deptId});
                            </script>
                        </div>
                        <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>
                        <a href="/employee/input.do" class="btn btn-success btn_redirect">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                        <#--批量删除-->
                        <a href="#" class="btn btn-danger btn_abtchDelete">
                            <span class="glyphicon glyphicon-trash"></span> 批量删除
                        </a>
                        <#--文件上传-->
                        <a href="#" class="btn btn-warning btn-import">
                            <span class="glyphicon glyphicon-import"></span> 导入
                        </a>
                        <#--文件下载-->
                        <a href="/employee/exportxls.do" class="btn btn-warning">
                            <span class="glyphicon glyphicon-export"></span> 导出
                        </a>
                    </form>
                </div>
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th><input type="checkbox" id="allcb"></th>
                        <th>编号</th>
                        <th>名称</th>
                        <th>email</th>
                        <th>年龄</th>
                        <th>部门</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <#list result.list as entity>
                        <tr>
                            <td><input type="checkbox" class="cb" data-ids='${entity.id!}'></td>
                            <td>${entity_index+1}</td>
                            <td>${entity.name!}</td>
                            <td>${entity.email!}</td>
                            <td>${entity.age!}</td>
                            <#--！只能处理前面第一个属性 -->
                            <td>${(entity.dept.name)!"暂未指定部门"}</td>
                            <td>
                                <a href="/employee/input.do?id=${entity.id}" class="btn btn-info btn-xs btn_redirect">
                                    <span class="glyphicon glyphicon-pencil"></span> 编辑
                                </a>
                                <a href="#" class="btn btn-danger btn-xs btn_delete" data-id='${entity.id}'>
                                    <span class="glyphicon glyphicon-trash"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>
                </table>
                <!--分页-->
                <#include "../common/page.ftl">
            </div>
        </section>
    </div>
    <#include  "../common/footer.ftl">
</div>
<#--模态框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">员工导入</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/employee/importXls.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">导入文件： </label>
                        <div class="col-sm-6">
                            <input type="file" name="file">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <#--地址写下载模板文件躲在的路径即可-->
                        <div class="col-sm-3">
                            <div class="col-sm-6">
                                <a href="/xlstemplates/employee_import.xls" class="btn btn-success">
                                    <span class="glyphicon glyphicon-export"></span> 下载模板
                                </a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submitsave">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
